package com.bawei.room_test;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = "MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
//        //获得dao增删改查
        StudentDao studentDao = AppDataBase.getInstance().getStudentDao();
        /*************添加数据***********/
        Student student2 = new Student(2, "占三2", 29);
        Student student3 = new Student(3, "占三3", 39);
        Student student4 = new Student(4, "占三3", 39);
        Student student5 = new Student(5, "占三3", 39);
        ArrayList<Student> students = new ArrayList<>();
        students.add(student2);
        students.add(student3);
        students.add(student4);
        students.add(student5);
        studentDao.insertList(students);
        Log.d(TAG, "添加后: "+studentDao.selectAll());
//        /*************修改数据***********/
//        student2.setUsername("里斯");
//        studentDao.update(student2);
//        Log.d(TAG, "修改后: "+studentDao.selectAll());
//        /*************条件查询***********/
//        Log.d(TAG, "条件查询: "+studentDao.selectByName("里斯"));
//        /*************删除数据***********/
//        studentDao.delete(student2);
//        Log.d(TAG, "删除一条后: "+studentDao.selectAll());
//        ArrayList<Student> list = new ArrayList<>();
//        list.add(student4);
//        list.add(student5);
//        studentDao.deleteList(list);
//        Log.d(TAG, "删除多条数据后: "+studentDao.selectAll());
//        studentDao.deleteAll();
//        Log.d(TAG, "删除全部后: "+studentDao.selectAll());


    }
}